//
//  WBEmoticonButton.swift
//  Weibo
//
//  Created by xu on 2017/3/31.
//  Copyright © 2017年 xuantong. All rights reserved.
//

import UIKit

class WBEmoticonButton: UIButton {
    
    var emoticonModel: WBEmoticonModel?{
         // 给其添加一个属性辨别哪个按钮点
        didSet{
            //显示
            self.isHidden = false
            // 赋值 (如果emoji表情 赋值的title  如果是图片表情 赋值的image)
            if emoticonModel?.isEmoji == true {
                // 获取code
                let code = ((emoticonModel?.code ?? "") as NSString)
                
                // 设置title
                self.setTitle(code.emoji(), for: UIControlState.normal)
                self.setImage(nil, for: UIControlState.normal)
            }else{
                // 图片表情
                let image = UIImage(named: emoticonModel?.allPath ?? "",in:WBEmoticonTools.shared.emoticonsBundle,compatibleWith: nil)
                self.setImage(image, for: UIControlState.normal)
                self.setTitle(nil, for: UIControlState.normal)
                
                
            }
            
        }
        
        
    }
  
}
